package cn.schoolwow.quickdao.module.database.ddl.query.flow.property;

import cn.schoolwow.quickdao.domain.database.parent.DatabaseType;
import cn.schoolwow.quickdao.domain.entity.Property;
import cn.schoolwow.quickdao.module.database.ddl.query.flow.property.getProperty.*;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

public class GetPropertyFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        DatabaseType databaseType = flowContext.checkInstanceData(DatabaseType.class);
        switch (databaseType){
            case H2:{
                flowContext.executeFlowList(new GetPropertyByH2Flow());
            }break;
            case SQLite:{
                flowContext.executeFlowList(new GetPropertyBySQLiteFlow());
            }break;
            case Mysql:
            case MariaDB:{
                flowContext.executeFlowList(new GetPropertyByMySQLFlow());
            }break;
            case Postgresql:{
                flowContext.executeFlowList(new GetPropertyByPostgresFlow());
            }break;
            case SQLServer:{
                flowContext.executeFlowList(new GetPropertyBySQLServerFlow());
            }break;
            case Oracle:{
                flowContext.executeFlowList(new GetPropertyByOracleFlow());
            }break;
        }
        Property property = (Property) flowContext.getData("property");
        if(null!=property){
            if (property.columnType.contains("(") && property.columnType.contains(")")) {
                property.range = property.columnType.substring(property.columnType.indexOf("(") + 1, property.columnType.indexOf(")"));
                property.columnType = property.columnType.substring(0, property.columnType.indexOf("("));
            }
        }
    }

    @Override
    public String name() {
        return "获取数据库表字段列表";
    }

}
